package io.xccit.race.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.xccit.common.core.controller.BaseController;
import io.xccit.common.core.domain.AjaxResult;
import io.xccit.race.service.IRaceCompetitionSignupService;

/**
 * 用户统计信息Controller
 * 
 * @author ywx
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/race/user/stats")
public class RaceUserStatsController extends BaseController
{
    @Autowired
    private IRaceCompetitionSignupService raceCompetitionSignupService;

    /**
     * 获取当前用户的统计信息
     */
    @GetMapping("/my")
    public AjaxResult getMyStats()
    {
        Long userId = getUserId();
        System.out.println("获取用户统计信息 - 用户ID: " + userId);
        
        // 获取用户参赛次数
        Long participationCount = raceCompetitionSignupService.countSignupByUserId(userId);
        System.out.println("用户参赛次数: " + participationCount);
        
        // 获取用户获奖次数（这里可以根据实际业务逻辑调整）
        Long awardCount = raceCompetitionSignupService.countAwardByUserId(userId);
        System.out.println("用户获奖次数: " + awardCount);
        
        // 构建用户统计信息
        Map<String, Object> userStats = new HashMap<>();
        userStats.put("participationCount", participationCount != null ? participationCount : 0);
        userStats.put("awardCount", awardCount != null ? awardCount : 0);
        userStats.put("userId", userId);
        
        System.out.println("返回的用户统计信息: " + userStats);
        return success(userStats);
    }
}
